import axios from 'axios'

// 创建axios实例
const service = axios.create({
  //baseURL: process.env.BASE_API,
  baseURL: process.env.BASE_API == "" ? window.location.href.split(":8888")[0]+":8888/api" : process.env.BASE_API ,
  // baseURL:  window.location.href.split(":8080")[0]+":8080/SystemCheck/api",
  timeout: 5000 // 请求超时时间
})

// request拦截器
service.interceptors.request.use(
  config => {
    config.headers.contentType = 'application/json'
    return config
  },
  error => {
    // Do something with request error
    console.log(error) // for debug
    Promise.reject(error)
  }
)

// response 拦截器
service.interceptors.response.use(
  response => response,
  error => {
    console.log('err' + error) // for debug
    return Promise.reject(error)
  }
)

export default service
